package edu.tapestry.iddb.client.pages.profil;

import iddb.AbstractResponse;
import iddb.OkResponse;

import org.apache.tapestry5.annotations.ApplicationState;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;

import edu.tapestry.iddb.client.entities.Profil;
import edu.tapestry.iddb.client.pages.ErrorPage;
import edu.tapestry.iddb.client.pages.OKPage;
import edu.tapestry.iddb.client.webService.CommandsGenerator;
import edu.tapestry.iddb.client.webService.IDDBProxy;

public class SwitchProfil {

	@Property
	private Profil profil;

	@ApplicationState
	private IDDBProxy proxy;

	@InjectPage
	private OKPage ok;

	@InjectPage
	private ErrorPage error;

	
	Object onActionFromSwitch() {

		AbstractResponse resp = proxy.execute(CommandsGenerator
				.createSwitchProfil(profil.getName(), profil.getType()));

		if (resp instanceof OkResponse){
			return ok;
		}
		else {
			return error.initialize(resp);
		}
	}
	
	
}
